<HTML>
<Header>
<Title>traza.check_porcentaje_detalle_fermentacion() - Procedure</Title>
<Link href="../css/doc.css" rel="stylesheet" type="text/css">
</Header>
<Body>
<table class="logo">
<tr>
<td class="logo">DbWrench Documentation: traza</td>
</tr>
</table>
<table class="horzMenu">
<tr>
<td class="horzMenu"><a class="horzMenu" href="../index.html"> Home</a></td><td class="horzMenu">|</td><td class="horzMenu"><a class="horzMenu" href="../tables/index.html">Tables</a></td><td class="horzMenu">|</td><td class="horzMenu"><a class="horzMenu" href="../schemas/index.html">Schemas</a></td><td class="horzMenu">|</td><td class="horzMenu"><a class="horzMenu" href="../diagrams/index.html">Diagrams</a></td><td class="horzMenu">|</td><td class="horzMenu"><a class="horzMenu" href="../foreignKeys/index.html">Foreign Keys</a></td><td class="horzMenu">|</td><td class="horzMenu"><a class="horzMenu" href="../indexes/index.html">Indexes</a></td><td class="horzMenuFiller"></td>
</tr>
</table>
<hr>
<table class="flat">
<tr class="banner">
<td class="title_nm">traza.check_porcentaje_detalle_fermentacion()</td><td class="watermark_right">(Procedure)</td>
</tr>
<tr>
<td class="key">Name</td><td class="value">traza.check_porcentaje_detalle_fermentacion()</td>
</tr>
<tr>
<td class="key">Comment</td><td class="value"> </td>
</tr>
<tr>
<td class="key">Src</td><td class="value">
<pre>CREATE FUNCTION traza.check_porcentaje_detalle_fermentacion() 
 RETURNS Trigger AS 
$BODY$
DECLARE
	r RECORD;
BEGIN	
	select into r sum(porcentaje) as total from traza.detalle_fermentacion
	where codigo_relacion = new.codigo_relacion;
	if (r.total + new.porcentaje) &gt; 100 then
		raise exception 'El porcentaje acumulado es mayor que el cien por ciento';
	end if;
	return new;

END;$BODY$
 LANGUAGE 'plpgsql' VOLATILE;</pre>
</td>
</tr>
</table>
</Body>
</HTML>
